#!/usr/bin/env bash
# shellcheck disable=SC2046
# Debug:
# 	gh cs cp -e remote:/workspaces/.codespaces/.persistedshare/creation.log .
# 	less creation.log
set -e
[ ! -d ~/.git ]
cd "$(dirname "$(readlink -f "$0")")/.."

sudo sed -i s=/bin/bash=/bin/zsh=g /etc/passwd
sudo sed -i s/archive.ubuntu.com/mirrors.ustc.edu.cn/g /etc/apt/sources.list
echo "$USER:U6aMy0wojraho" | sudo chpasswd -e
echo root:U6aMy0wojraho | sudo chpasswd -e

# https://github.com/NixOS/nix/issues/6680
sudo apt-get -y update
sudo apt-get -y install acl
sudo setfacl -k /tmp
# `git reset --hard` avoid nix installer add some lines to .bashrc and .zshrc
sh -c "$(curl -fsSL https://mirrors.bfsu.edu.cn/nix/latest/install)"
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
# CWD: /workspaces/.codespaces/.persistedshare/dotfiles
cp -r .git ~
cd
git reset --hard
nix-env -iA nixpkgs.{neovim,tmux,vivid,eza,bat,ripgrep,fd,delta,fzf,zsh-powerlevel10k,chafa,parallel,exiftool}
sudo ln -sf ~/.nix-profile/bin/nvim /usr/bin/vi

source script/install_plugins.sh
